import { ref } from "vue";
import{ElMessage,ElLoading}from"element-plus";
import type {FormInstance} from "element-plus"

export const useFunc=()=>{
    let formModel=ref({
        username:"",
        password:"",
        code:"",
        rememberMe:false
    })
    let formRef=ref()
    let code=ref()
    let picCodeRef=ref()
    let globalLoading=ref(false)
    return {formModel,formRef}

    const handleSubmit=(formRef: any)=>{
        const loading =ElLoading.service({
            lock:true,
            text:'Loading',
            background:'rgba(0,0,0,0.7)',
        })
        globalLoading.value=true;
        setTimeout(()=>{
            loading.close()
            ElMessage({
                message:'登录成功',
                type:'success',
                plain:true,
            })
            globalLoading.value=false;
        },2000)
    }
    const handleReset=(formRef:FormInstance | undefined)=>{
        if(!formRef)return
        formRef.resetFields()
    } 

    return{formModel,formRef,code,picCodeRef,globalLoading,handleSubmit,handleReset}
}